package com.hl.sfzy.service.impl;

/**
 * @ClassName ArticleServiceImpl
 * @Description TODO
 * @Author 野原新之助
 * @Date 2024年01月15日 14:35:15
 * @Version 1.0
 */

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hl.sfzy.entity.Article;
import com.hl.sfzy.mapper.ArticleMapper;
import com.hl.sfzy.service.ArticleService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ArticleServiceImpl implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    public ArticleServiceImpl() {
    }

    public void add(Article entity) throws Exception {
        this.articleMapper.insert(entity);
    }

    public void edit(Article entity) {
        this.articleMapper.update(entity);
    }

    public void remove(Integer id) {
        this.articleMapper.delete(id);
    }

    public void removeBatch(Integer[] ids) {
        this.articleMapper.deleteBatch(ids);
    }

    public List<Article> find(Article entity) {
        return this.articleMapper.select(entity);
    }

    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, Article entity) {
        PageHelper.startPage(pageNum, pageSize);
        List<Article> articleList = this.articleMapper.select(entity);
        PageInfo<Article> pageInfo = new PageInfo(articleList);
        Map<String, Object> pageMap = new HashMap();
        pageMap.put("list", articleList);
        pageMap.put("total", pageInfo.getTotal());
        return pageMap;
    }

    public Article findById(Integer id) {
        return (Article) this.articleMapper.selectById(id);
    }
}
